package com.tjshop.android.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by gytaiSSD on 2015/1/6.
 */
public class MyCoupon {
	private String name;// "name": "乐峪29元6小时欢唱套餐",
	private String desc;// "desc": "仅售29元，价值300元火车站店6小时欢唱套餐2选1！",
	private String icon;// "icon":
						// "http://static.kenchao.com/Upload/201501/54b48ee5b5463.png",
	private String coupon_id;// "coupon_id": "8",
	private String end_time;// "end_time": "2016-01-01 23:59:59",
	private String add_time;// "add_time": "2015.01.25 01:06",
	private int flag;// "flag": 0,
	private String flag_name;// "flag_name": "未消费",
	private float price;// "price": 48.8

	public String getEnd_time() {
		return end_time;
	}

	public void setEnd_time(String end_time) {
		this.end_time = end_time;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getCoupon_id() {
		return coupon_id;
	}

	public void setCoupon_id(String coupon_id) {
		this.coupon_id = coupon_id;
	}

	public String getAdd_time() {
		return add_time;
	}

	public void setAdd_time(String add_time) {
		this.add_time = add_time;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public String getFlag_name() {
		return flag_name;
	}

	public void setFlag_name(String flag_name) {
		this.flag_name = flag_name;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public void parse(JSONObject data) {

		setPrice(getFloat(data, "price"));
		setFlag_name(getString(data, "flag_name"));
		setFlag(getInt(data, "flag"));
		setCoupon_id(getString(data, "coupon_id"));
		setAdd_time(getString(data, "add_time"));
		setName(getString(data, "name"));
		setDesc(getString(data, "desc"));
		setIcon(getString(data, "icon"));
		setEnd_time(getString(data, "end_time"));// private String
													// end_time;//"end_time":
													// "2016-01-01 23:59:59",
	}

	private float getFloat(JSONObject data, String id) {
		try {
			if (data.has(id)) {
				return (float) data.getDouble(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return 0;
	}

	public int getInt(JSONObject obj, String id) {
		try {
			if (obj.has(id)) {
				return obj.getInt(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return 0;
	}

	public String getString(JSONObject data, String id) {
		try {
			if (data.has(id)) {
				return data.getString(id);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
}
